﻿using _02;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyKTV
{
    public partial class Form3 : Form
    {
        DBHelper dBHelper = new DBHelper();
        DataSet ds = new DataSet();
        public Form3()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("请输入查询条件");
            }
            else
            {
                ds.Tables["ScheduleInfo"].Clear();
                dBHelper.OpenConnection();
           string sql = "select count,a.teamName as hostTeamId,b.teamName as awayTeamId,competitionTime,competitionPosition,score,entryPerson from ScheduleInfo inner join TeamInfo as a on a.id=ScheduleInfo.hostTeamId inner join TeamInfo as b on b.id = ScheduleInfo.awayTeamId where a.teamName like N'%"+this.textBox1.Text+"%'";
            SqlCommand com = new SqlCommand(sql, dBHelper.Connection);
            SqlDataReader read = com.ExecuteReader();
            while (!read.HasRows)
            {
                MessageBox.Show("没有该内容");
                this.textBox1.Text = null;
                read.Close();
                dBHelper.CloseConnection();
                return;
            }
                read.Close();

               
                SqlDataAdapter m = new SqlDataAdapter(sql, dBHelper.Connection);
                m.Fill(ds, "ScheduleInfo");
                this.dataGridView1.DataSource = ds.Tables["ScheduleInfo"];
                dBHelper.CloseConnection();
               
        }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            dBHelper.OpenConnection();
            string sql1 = "select count,a.teamName as hostTeamId,b.teamName as awayTeamId,competitionTime,competitionPosition,score,entryPerson from ScheduleInfo inner join TeamInfo as a on a.id=ScheduleInfo.hostTeamId inner join TeamInfo as b on b.id = ScheduleInfo.awayTeamId";
            SqlDataAdapter m = new SqlDataAdapter(sql1, dBHelper.Connection);
            m.Fill(ds, "ScheduleInfo");
            this.dataGridView1.DataSource = ds.Tables["ScheduleInfo"];
            dBHelper.CloseConnection();
        }
    }
    }

